//package com.hbase.dao.impl;
//
//import com.hbase.dao.TestDao;
//import com.hbase.utils.ByteUtils;
//import com.hbase.vo.MessageVo;
//import com.hbase.vo.Tables;
//import com.navercorp.pinpoint.common.buffer.Buffer;
//import com.navercorp.pinpoint.common.buffer.FixedBuffer;
//import com.navercorp.pinpoint.common.hbase.HbaseOperations2;
//import com.navercorp.pinpoint.common.hbase.RowMapper;
//import com.sematext.hbase.wd.AbstractRowKeyDistributor;
//import org.apache.hadoop.hbase.client.Put;
//import org.apache.hadoop.hbase.client.Result;
//import org.apache.hadoop.hbase.client.Scan;
//import org.apache.solr.client.solrj.impl.HttpSolrServer;
//import org.apache.solr.common.SolrInputDocument;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Repository;
//
///**
// * @author roadhog
// */
//@Repository
//public class TestDaoImpl implements TestDao {
//
//    @Autowired
//    private HbaseOperations2 hbaseTemplate;
//
//    @Autowired
//    @Qualifier("traceIdToApmTransactionDistributor")
//    private AbstractRowKeyDistributor rowKeyDistributor;
//
//    public static HttpSolrServer solrServer = new HttpSolrServer("http://172.21.0.98:8983/solr");
//
//    @Override
//    public String insertMessage(MessageVo messageVo) {
//
//
//        final byte[] operatorIndexRowKey = ByteUtils.longToBytes(messageVo.getRowkey());
//        Put put = new Put(operatorIndexRowKey);
//        put.addColumn(Tables.TEST_CF_C, Tables.TEST_C_NETWORK_TYPE, System.currentTimeMillis(), messageVo.getNetworkType().getBytes());
//        put.addColumn(Tables.TEST_CF_C, Tables.TEST_C_SYSTEM, System.currentTimeMillis(), messageVo.getSystem().getBytes());
//        put.addColumn(Tables.TEST_CF_C, Tables.TEST_C_VERSION, System.currentTimeMillis(), messageVo.getVersion().getBytes());
//        put.addColumn(Tables.TEST_CF_C, Tables.TEST_C_CPU_USE_TIME, System.currentTimeMillis(), ByteUtils.intToBytes(messageVo.getCpuUseTime()));
//        put.addColumn(Tables.TEST_CF_C, Tables.TEST_C_CLICK_COUNT, System.currentTimeMillis(), ByteUtils.intToBytes(messageVo.getClickCount()));
//
//        System.out.println(ByteUtils.intToBytes(messageVo.getCpuUseTime()).length);
//
//        boolean success = hbaseTemplate.asyncPut(Tables.TEST, put);
//        if (!success) {
//            hbaseTemplate.asyncPut(Tables.TEST, put);
//        }
////        log.info("OperatorDeviceTraceIndex表保存数据成功,traceId:{},operatorCode:{},resultCode:{}", index.getTraceId(), index.getOperatorCode(), index.getResultCode());
//
//        return null;
//    }
//
////    private Get createGet(String traceId) {
////
////        byte[] rowKey = encodeRowKey(traceId);
////        final Get get = new Get(rowKey);
////
////        get.addFamily(Tables.TRACEID_TO_APM_TRANSACTION_CF_C);
////
////        return get;
////    }
////
////    public byte[] encodeRowKey(String traceId) {
////        if (traceId == null) {
////            throw new NullPointerException("basicSpan must not be null");
////        }
////
////        byte[] rowKey = BytesUtils.toBytes(traceId);
////        return wrapDistributedRowKey(rowKey);
////    }
////
////    private byte[] wrapDistributedRowKey(byte[] rowKey) {
////        return rowKeyDistributor.getDistributedKey(rowKey);
////    }
//
//
//    @Override
//    public String queryMessage(MessageVo messageVo) {
//        Scan scan=new Scan();
//        scan.setStartRow(ByteUtils.longToBytes(messageVo.getRowkey()));
//
//        hbaseTemplate.find(Tables.TEST, scan, new RowMapper<MessageVo>() {
//
//            @Override
//            public MessageVo mapRow(Result result, int rowNum) throws Exception {
//
//                if (result.isEmpty()) {
//                    return null;
//                }
//
//
////                Cell[] rawCells = result.rawCells();
//                byte[] rowkey = result.getRow();
//
//                SolrInputDocument solrDoc = new SolrInputDocument();
//
//                final Buffer rowkeyBuffer = new FixedBuffer(rowkey);
//
//                MessageVo messageVo=new MessageVo();
//
//                messageVo.setRowkey(rowkeyBuffer.readLong());
//
//                //获取存在hbase表中的线程数,后台线程数,历史线程数
//                byte[] networkTypeByte = result.getValue(Tables.TEST_CF_C, Tables.TEST_C_NETWORK_TYPE);
//                byte[] systemByte = result.getValue(Tables.TEST_CF_C, Tables.TEST_C_SYSTEM);
//                byte[] versionByte = result.getValue(Tables.TEST_CF_C, Tables.TEST_C_VERSION);
//
//                byte[] cpuUseTimeByte = result.getValue(Tables.TEST_CF_C, Tables.TEST_C_CPU_USE_TIME);
//                byte[] clickCountByte = result.getValue(Tables.TEST_CF_C, Tables.TEST_C_CLICK_COUNT);
//
//                //将hbase表中存的byte转成可读数字,并放到mapper中
//                if(networkTypeByte!=null) {
//                    final Buffer networkTypeBuffer = new FixedBuffer(networkTypeByte);
//                    messageVo.setNetworkType(networkTypeBuffer.readPadString(networkTypeByte.length));
//                }
//                if(systemByte !=null) {
//                    final Buffer systemBuffer = new FixedBuffer(systemByte);
//                    messageVo.setSystem(systemBuffer.readPadString(systemByte.length));
//                }
//                if(versionByte!=null) {
//                    final Buffer versionBuffer = new FixedBuffer(versionByte);
//                    messageVo.setVersion(versionBuffer.readPadString(versionByte.length));
//                }
//                if(cpuUseTimeByte!=null) {
//                    final Buffer cpuUseTimeBuffer = new FixedBuffer(cpuUseTimeByte);
//                    Long cupUseTime=cpuUseTimeBuffer.readLong();
//                    messageVo.setCpuUseTime(cupUseTime.intValue());
//                }
//                if(clickCountByte!=null) {
//                    final Buffer clickCountBuffer = new FixedBuffer(clickCountByte);
//                    Long clickCount=clickCountBuffer.readLong();
//                    messageVo.setClickCount(clickCount.intValue());
//                }
//
//                solrDoc.addField("rowkey", messageVo.getRowkey());
//                solrDoc.addField("networkType", messageVo.getNetworkType());
//                solrDoc.addField("system", messageVo.getSystem());
//                solrDoc.addField("version", messageVo.getVersion());
//                solrDoc.addField("cpuUseTime", messageVo.getCpuUseTime());
//                solrDoc.addField("clickCount", messageVo.getClickCount());
//
//                solrServer.add(solrDoc);
//                solrServer.commit(true, true, true);
//
//                System.out.println(messageVo.toString());
//
//                return messageVo;
//            }
//        });
//
//        return null;
//
//    }
//}
